<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller {
	public function index(){
		if($this->session->userdata('groupid')&&$this->session->userdata('groupid') == 1){
			$data['view'] = "";
			$data['ac'] = "user";
			
			//page
			$this->load->library('pagination');
			$config['base_url'] =site_url('index.php/admin/index');
			$config['total_rows'] = $this->db->count_all('ci_user');
			$config['per_page'] = '15'; 
			$config['full_tag_open'] = '<p>';
   			$config['full_tag_close'] = '</p>';
			
			$this->pagination->initialize($config); 
			
			$data['page'] =  $this->pagination->create_links();
			
			//user list
			$gridrows = array();
			$this->load->model('User_model');
			$query= $this->User_model->get_user($config['per_page'],$this->uri->segment(3));
			foreach( $query->result() as $row){
				array_push($gridrows,array($row->uid,$row->username,$row->groupname,$row->email,date('Y-m-d',$row->reg_time)));
			}
			
			$this->load->library('table');
			$this->table->set_heading('UID','Username','Group','Email','Register Time');
			$tmpl = array ( 'table_open'  => '<table border="1" cellpadding="2" cellspacing="1" class="table">',
				'row_alt_start' => '<tr class="alt">',
				'row_alt_end' => '</tr>',
				'cell_alt_start' => '<td>',
				'cell_alt_end'  => '</td>',
			);
			$this->table->set_template($tmpl); 
			$data['grid'] = $this->table->generate($gridrows); 
	
			$this->load->view('correction/header',$data);
			$this->load->view('admin/sider');
			$this->load->view('admin/admin');
			$this->load->view('correction/footer');
		}else{
			redirect(base_url());
		}
	}
}
?>